//
//  Fatcat.swift
//  AutoPrint
//
//  Created by 胡玉葱 on 16/9/25.
//  Copyright © 2016年 fatcat. All rights reserved.
//

import UIKit

class Fatcat: NSObject {
    
    static let SERVER_DOMAIN_NAME:String = "\(baseDomainName)/print/"
    //username=&password=&verify=
    
    static let USER_LOGIN:String = "admin/userLogin.php"
    
    static let GET_VERIFY:String = "admin/getVerify.php"
    
    static let FILE_API:String = "api.php"
    
    static let TEST_GETLIST:String = "lib/getList.php"
    
    static let THEME_COLOR: UIColor = themeColor2//UIColor(red: 1.0/255.0, green: 121.0/255.0, blue: 106.0/255.0, alpha: 1)
    
    static let SUPPORTED_TYPES = ["doc","docx","ppt","txt","pptx","pdf","png","bmp","jpg","jpeg"]
    
    static let PRICE_PRE_PAGE: Double = 0.1
    
    static let PRICE_PRE_COLOR_PAGE: Double = 1.0
    
    static let DELIVER_PRICE: Double = 1.0
    
    static let FREE_DELIVER_MIN: Int = 10
    
    static let PREVIEW_BASE_URL = "http://dcs.yozosoft.com:8000/"
    
    static let SELECTED_COLOR = UIColor(red: 96.0/255.0, green: 156.0/255.0, blue: 255.0/255.0, alpha: 1)
    
    static let payMethods:[[String: String]] = [["id":"alipay", "name":"支付宝"]]
    
    static let ORDER_UNPAY_EXPIRE_TIME:Int = 10
    
    static let PRODUCT_NAME = "喵印"
    
    static let AMAP_API_KEY = "e6a88014ff83cb858e503aeae4d87357"
    
    //act=uploadFile&pNum=&isShare=&cId=&printFile
    
    //act=checkFile&fileMd5=
    
    //act=getList&page=
    
    //act=submitOrder&name=&province=&city=&area=&phone=&address=&totalPrice=&postMethod=&payMethod=&remark=&goods_number=
    
    //act=submitOrder&name=&province=&city=&area=&phone=&address=&totalPrice=&postMethod=&payMethod=&remark=&goods_number=
    
    static func getFileSize(_ filepath: String) -> String? {
        let fileAttr = try? FileManager.default.attributesOfItem(atPath: filepath)
        
        if fileAttr != nil{
            let fileSize = fileAttr![FileAttributeKey.size] as! Int
            //sizeToShow = "\(fileSize)B"
            
            
            if fileSize >= 1024{
                let fileSizeDouble = Double(fileSize)
                var dividedDouble = fileSizeDouble/1024.0
                if dividedDouble < 1024 {
                    return String(format: "%0.2fKB", dividedDouble)
                }else{
                    dividedDouble = dividedDouble/1024.0
                    if dividedDouble < 1024{
                        return String(format: "%0.2fMB", dividedDouble)
                        
                    }else{
                        dividedDouble = dividedDouble/1024.0
                        if dividedDouble < 1024{
                            return String(format: "%0.2fGB", dividedDouble)
                        }
                    }
                    
                }
                
            }
        }
        
        return nil
    }
    
}

